package com.bdzl.biz.controller;

import java.util.List;
import java.util.Map;

import com.bdzl.pub.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bdzl.pub.entity.loan.OrderMailDO;
import com.bdzl.biz.service.OrderMailService;
import com.bdzl.pub.util.param.PageUtils;
import com.bdzl.pub.util.param.Query;
import com.bdzl.pub.util.param.R;

/**
 * 贷款资料邮寄信息表
 *
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-05-11 15:23:42
 */

@Controller
@RequestMapping("/bdzl/orderMail")
public class OrderMailController extends BaseController {
	@Autowired
	private OrderMailService orderMailService;

	@GetMapping()
	String OrderMail(){
	    return "bdzl/orderMail/orderMail";
	}

	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<OrderMailDO> orderMailList = orderMailService.list(query);
		int total = orderMailService.count(query);
		PageUtils pageUtils = new PageUtils(orderMailList, total);
		return pageUtils;
	}

	@GetMapping("/add")
	String add(){
	    return "bdzl/orderMail/add";
	}

	@GetMapping("/edit/{mailId}")
	String edit(@PathVariable("mailId") Integer mailId,Model model){
		OrderMailDO orderMail = orderMailService.get(mailId);
		model.addAttribute("orderMail", orderMail);
	    return "bdzl/orderMail/edit";
	}

	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save( OrderMailDO orderMail){
		if(orderMailService.save(orderMail)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update( OrderMailDO orderMail){
		orderMailService.update(orderMail);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove( Integer mailId){
		if(orderMailService.remove(mailId)>0){
		return R.ok();
		}
		return R.error();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] mailIds){
		orderMailService.batchRemove(mailIds);
		return R.ok();
	}

}
